﻿using UnityEngine;
using System.Collections;
using System;
using System.Text.RegularExpressions;
using FutureCode.Game.Command;
using System.Text;
using System.Collections.Generic;

public class GameController : MonoBehaviour {
    public bool Started { get; private set; }
    public GameObject HostSettingPanel;
    public GameObject SoldierPrefab;
    public UISlider BloodBar;
    public GameObject ControlPanelObject;
    public GameObject MonstersObject;
    public GameObject NetManagerObject;
    public static GameController Instance;
    NetManager net;
    GameSettings settings;
	// Use this for initialization
    void Awake()
    {
        Instance = this;
    }
	void Start () {
        net = NetManager.Instance;
        settings = GameSettings.Instance;
	}
	
	// Update is called once per frame
	void Update () {
        if(!Started && net.Connected)
        {
            Started = true;
            StartGame();
        }
	}

    private void StartGame()
    {
        if(settings.IsPlayerClient)
        {
            CreateSoldier();
            ControlPanelObject.SetActive(true);
        }
        MonstersObject.SetActive(true);
    }

    public void CreateSoldier()
    {
        var pos = new Vector3(25f, 0, 25f);
        CreateSoldier(pos);
    }
    public void CreateSoldier(Vector3 position)
    {
        var player = GameObject.Instantiate(SoldierPrefab, position, Quaternion.identity) as GameObject;
        settings.Player = player;
        GameObject.FindWithTag("MainCamera").GetComponent<CameraController>().Target = settings.Player.transform;
        BloodBar.gameObject.SetActive(true);
    }
}
